package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtilJyjc;
import com.ruoyi.system.domain.JyjcImportLbys;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JyjcUserNum;
import com.ruoyi.system.service.IJyjcUserNumService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 各部所人员数Controller
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/system/jyjcUserNum")
public class JyjcUserNumController extends BaseController
{
    @Autowired
    private IJyjcUserNumService jyjcUserNumService;

    /**
     * 查询各部所人员数列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(JyjcUserNum jyjcUserNum)
    {
        startPage();
        List<JyjcUserNum> list = jyjcUserNumService.selectJyjcUserNumList(jyjcUserNum);
        return getDataTable(list);
    }

    /**
     * 导出各部所人员数列表
     */
    @Anonymous
    @Log(title = "各部所人员数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JyjcUserNum jyjcUserNum)
    {
        List<JyjcUserNum> list = jyjcUserNumService.selectJyjcUserNumList(jyjcUserNum);
        ExcelUtil<JyjcUserNum> util = new ExcelUtil<JyjcUserNum>(JyjcUserNum.class);
        util.exportExcel(response, list, "各部所人员数数据");
    }

    /**
     * 获取各部所人员数详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jyjcUserNumService.selectJyjcUserNumById(id));
    }

    /**
     * 新增各部所人员数
     */
    @Anonymous
    @Log(title = "各部所人员数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JyjcUserNum jyjcUserNum)
    {
        return toAjax(jyjcUserNumService.insertJyjcUserNum(jyjcUserNum));
    }

    /**
     * 修改各部所人员数
     */
    @Anonymous
    @Log(title = "各部所人员数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JyjcUserNum jyjcUserNum)
    {
        return toAjax(jyjcUserNumService.updateJyjcUserNum(jyjcUserNum));
    }

    /**
     * 删除各部所人员数
     */
    @Anonymous
    @Log(title = "各部所人员数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jyjcUserNumService.deleteJyjcUserNumByIds(ids));
    }
    @Anonymous
    @Log(title = "各部所人员数", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, String yearyf) throws Exception
    {
        ExcelUtilJyjc<JyjcUserNum> util = new ExcelUtilJyjc<JyjcUserNum>(JyjcUserNum.class);
        List<JyjcUserNum> jyjcSharingExpensesSumList = util.importExcel(file.getInputStream(),3);

        String message = jyjcUserNumService.importJyjcUserNum(jyjcSharingExpensesSumList, yearyf);
        return success(message);
    }
    @Anonymous
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JyjcUserNum> util = new ExcelUtil<JyjcUserNum>(JyjcUserNum.class);
        util.importTemplateExcel(response, "各部所人员数");
    }
}
